package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 商品表（SPU） Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-09-11
 */
@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Select("<script>" +
            "SELECT M.* FROM ( " +
            "select aa.*, au.name as productUnitName, ab.name as categoryName from dragon_product aa " +
            "left join dragon_product_unit au on aa.product_unit_id = au.id  " +
            "left join dragon_product_category ab on aa.category_id = ab.id ) M " +
            "WHERE 1=1  " +
            "<if test='categoryId != null and categoryId != \"\"'> "+
            " and M.category_id = #{categoryId} " +
            "</if> " +
            "<if test='search != null and search != \"\"'> "+
            " and M.name like CONCAT('%',#{search},'%')  " +
            "</if> " +
            "</script>")
    Page<Product> selectListByItem(Page<Product> productSpecsPage, Integer categoryId , String search);

}
